/*
 * @LastEditors: w
 */
// `<script src="https://screeps-cn.gitee.io/screeps-chinese-pack-release/main.js" async defer></script>`
import { errorMapper } from './modules/errorMapper'
import { sayHello } from './modules/utils'
import harvester from './modules/harvester'
/**
 * 全局统计信息扫描器
 * 负责搜集关于 cpu、memory、GCL、GPL 的相关信息
 */
 const stateScanner = function () {
    // 每 20 tick 运行一次
    if (Game.time % 20) return 
  
    if (!Memory.stats) Memory.stats = {}
    
    // 统计 GCL / GPL 的升级百分比和等级
    Memory.stats.gcl = (Game.gcl.progress / Game.gcl.progressTotal) * 100
    Memory.stats.gclLevel = Game.gcl.level
    Memory.stats.gpl = (Game.gpl.progress / Game.gpl.progressTotal) * 100
    Memory.stats.gplLevel = Game.gpl.level
    // CPU 的当前使用量
    Memory.stats.cpu = Game.cpu.getUsed()
    // bucket 当前剩余量
    Memory.stats.bucket = Game.cpu.bucket
}
Game.spawns['Spawn1'].spawnCreep( [WORK,WORK, CARRY, MOVE], 'Harvester1' );
export const loop = errorMapper(() => {
    var creep = Game.creeps['Harvester1'];
    console.log(creep.carry.energy,creep.carryCapacity);
    if(creep.carry.energy < creep.carryCapacity) {
        var sources = creep.room.find(FIND_SOURCES);
        if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(sources[0]);
        }
    } else {
        if( creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE ) {
            creep.moveTo(Game.spawns['Spawn1']);
        }
    }
    // 统计全局资源使用
    // stateScanner()
})